package com.lanlian.cayman.dialog;

import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;

import com.lanlian.cayman.R;
import com.lanlian.cayman.activity.KLineHengPingActivity;
import com.lanlian.cayman.activity.ZixuanActivity;

/**
 * <pre>
 *     date   : 2018/8/22 20:09
 *     desc   : K线选择对话框
 *     version: 1.0
 * </pre>
 */
public class KlineSelectDialog extends Dialog implements View.OnClickListener {

    private KLineHengPingActivity mContext;
    private View iv_chicang;
    private View iv_zhixuan;
    private View iv_hangqing;
    private View ll_drawline;
    private ImageView iv_close;
    private View view;

    public KlineSelectDialog(@NonNull Context context) {
        super(context, R.style.customDialog1);
        this.mContext = (KLineHengPingActivity) context;
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.width = lp.MATCH_PARENT;
        lp.height = lp.MATCH_PARENT;
        lp.gravity = Gravity.RIGHT | Gravity.BOTTOM;
        onWindowAttributesChanged(lp);
        setCanceledOnTouchOutside(true);
        getWindow().setAttributes(lp);
        getWindow().getDecorView().setPadding(0, 0, 0, 0);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_klineselect);
        initView();
    }

    private void initView() {
        iv_close = findViewById(R.id.iv_close);
        iv_chicang = findViewById(R.id.iv_chicang);
        iv_zhixuan = findViewById(R.id.iv_zhixuan);
        iv_hangqing = findViewById(R.id.iv_hangqing);
        ll_drawline = findViewById(R.id.ll_drawline);
        iv_chicang.setOnClickListener(this);
        iv_zhixuan.setOnClickListener(this);
        iv_hangqing.setOnClickListener(this);
        iv_close.setOnClickListener(this);
        ll_drawline.setOnClickListener(this);
        if (mContext.klineType == 0) {
            ll_drawline.setVisibility(View.GONE);
        } else {
            ll_drawline.setVisibility(View.VISIBLE);
        }
    }

    @Override
    public void onClick(View v) {
        Intent intent = new Intent();
        int id = v.getId();
        switch (id) {
            case R.id.iv_close:
                dismiss();
                break;
            case R.id.iv_chicang:
                dismiss();
                mContext.setItem(1);
                mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                break;
            case R.id.iv_zhixuan:
                intent.setClass(mContext, ZixuanActivity.class);
                mContext.startActivity(intent);
                break;
            case R.id.ll_drawline:
//                mContext.popupWindow=new DrawLinePopup(mContext);
//                mContext.popupWindow.show(view);
                mContext.kline.showDrawUtil();
                dismiss();
                break;
            case R.id.iv_hangqing:
                dismiss();
                mContext.setItem(0);
                mContext.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
                break;
            default:
                break;
        }
    }

    public void showDialog(View view) {
        this.view = view;
        show();
    }

}
